//
//  BigCell.m
//  卢卡的时光网
//
//  Created by 卡神 on 15/7/26.
//  Copyright © 2015年 lok. All rights reserved.
//

#import "BigCell.h"
#import "UIViewExt.h"
#import "UIImageView+WebCache.h"

@implementation BigCell

#pragma mark -init
- (nonnull instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        CGFloat width = self.width * 0.9;//uiviewext
        CGFloat height = self.height * 0.9;
        _image = [[UIImageView alloc] initWithFrame:CGRectMake((self.width - width) / 2, (self.height - height) / 2, width, height)];
        [self.contentView addSubview:_image];
        [self createDetailView];
    }
    return self;
}
- (void)createDetailView {
    _detail = [[NSBundle mainBundle] loadNibNamed:@"PosterDetailView" owner:self options:nil].lastObject;
    _detail.frame = _image.frame;
    _detail.hidden = YES;
    [self.contentView addSubview:_detail];
}


#pragma mark -setImage and FlipView

- (void)setMovie:(MoiveInformation *)movie {
    _movie = movie;
    _detail.model = _movie;
    [self setNeedsLayout];
}

- (void)layoutSubviews {
    _detail.hidden = YES;
    NSString *imageUrl = [self.movie.images valueForKey:@"large"];
    [_image sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"7"]];
}

- (void)flip {
    UIViewAnimationOptions option = _detail.hidden ? UIViewAnimationOptionTransitionFlipFromRight : UIViewAnimationOptionTransitionFlipFromLeft;
    [UIView transitionWithView:self duration:0.5 options:option animations:nil completion:nil];
    _detail.hidden = !_detail.hidden;
}



@end
